package wox.lonice.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wox.lonice.dao.ProxyIpMapper;
import wox.lonice.entity.ProxyIp;
import wox.lonice.service.ProxyIpService;
import wox.lonice.utis.IpProxyUtil;

import java.util.List;

@Service
public class ProxyIpServiceImpl implements ProxyIpService {

    @Autowired
    private ProxyIpMapper proxyIpMapper;

    @Override
    public void getProxyIp(){
        List<ProxyIp> proxyIpList = IpProxyUtil.getIpMessage();
        if(CollectionUtil.isNotEmpty(proxyIpList)){
            //先删除所有
            proxyIpMapper.deleteAll();
            //然后重新插入所有
            proxyIpList.forEach(proxyIp -> proxyIpMapper.insert(proxyIp));
        }
    }

}
